package com.shuai.frame.protocol;

import lombok.Getter;

@Getter
public enum ProtocolMessageSerializerEnum {
    JDK(0, "jdk"),
    JSON(1, "json"),
    KRYO(2, "kryo"),
    HESSIAN(3, "hessian");

    private final int code;
    private final String desc;

    ProtocolMessageSerializerEnum(int code, String desc) {
        this.code = code;
        this.desc = desc;
    }

    public static ProtocolMessageSerializerEnum getEnum(int code) {
        for (ProtocolMessageSerializerEnum protocolMessageSerializerEnum : ProtocolMessageSerializerEnum.values()) {
            if (protocolMessageSerializerEnum.getCode() == (code)) {
                return protocolMessageSerializerEnum;
            }
        }
        return null;
    }

    public static ProtocolMessageSerializerEnum getEnumByDesc(String desc) {
        for (ProtocolMessageSerializerEnum protocolMessageSerializerEnum : ProtocolMessageSerializerEnum.values()) {
            if (protocolMessageSerializerEnum.getDesc().equals(desc)) {
                return protocolMessageSerializerEnum;
            }
        }
        return null;
    }
}
